package com.coolw.test.oom;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * 模拟堆内存溢出（无限创建对象，直到发生OutOfMemoryError
 * <p>
 * 设置jvm参数
 * -Xms10M -Xmx10M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=./dump.hprof
 * <p>
 * -Xms10M  堆最小内存10M
 * -Xmx10M  堆最大内存10M
 * -XX:+HeapDumpOnOutOfMemoryError  内存溢出时自动生成堆内存快照
 * -XX:HeapDumpPath=./dump.hprof  内存快照保存位置，不指定默认当前路径
 *
 * @author coolw
 * @date 2024/1/25 11:42
 */
public class OutOfMemoryDemo {

    public static void main(String[] args) {
        List<User> userList = new ArrayList<>();
        while (true) {
            userList.add(new User());
        }
    }

    @Data
    static class User {

        private String username;

        private String password;

        private String address;
    }
}
